Security News
PyPI Introduces Digital Attestations to Strengthen Python Package Security
PyPI now supports digital attestations, enhancing security and trust by allowing package maintainers to verify the authenticity of Python packages.
vite-plugin-svgr
Advanced tools
The vite-plugin-svgr package allows you to import SVG files as React components in your Vite projects. This enables you to easily manipulate and use SVG images within your React applications, offering a streamlined workflow for working with SVGs.
Import SVG as a React Component
This feature allows you to import an SVG file directly as a React component, which you can then use in your JSX just like any other component. This simplifies the process of using SVGs in your application, making them more flexible and easier to style or manipulate.
import { ReactComponent as Logo } from './logo.svg';
function App() {
return (
<div>
<Logo />
</div>
);
}
Customize SVGs with SVGR Options
This feature leverages SVGR options to customize SVGs when they are imported as React components. You can pass props to the SVG component to dynamically change its properties, such as the title, fill color, and more. This adds a layer of flexibility in how SVGs are rendered and used within your application.
import { ReactComponent as Logo } from './logo.svg?svgr';
function App() {
return (
<div>
<Logo title="Logo Title" />
</div>
);
}
Similar to vite-plugin-svgr, @svgr/webpack allows you to import SVGs as React components in projects using Webpack. While vite-plugin-svgr is tailored for Vite projects, @svgr/webpack is designed for those that are built with Webpack, offering similar functionalities in terms of importing and customizing SVGs.
react-svg-loader provides functionality similar to vite-plugin-svgr by allowing SVGs to be imported as React components. However, it is another tool that integrates with Webpack. The main difference lies in the implementation and configuration specifics, with react-svg-loader offering its own set of options and features for handling SVGs in React projects.
Vite plugin to transform SVGs into React components. Uses svgr under the hood.
// vite.config.js
import svgr from 'vite-plugin-svgr'
export default {
// ...
plugins: [svgr()],
}
Then SVG files can be imported as React components, just like create-react-app does:
import { ReactComponent as Logo } from './logo.svg'
If you are using TypeScript, there is also a declaration helper for better type inference:
/// <reference types="vite-plugin-svgr/client" />
svgr({
// Set it to `true` to export React component as default.
// Notice that it will overrides the default behavior of Vite.
exportAsDefault: false,
// svgr options: https://react-svgr.com/docs/options/
svgrOptions: {
// ...
},
// esbuild options, to transform jsx to js
esbuildOptions: {
// ...
},
// A minimatch pattern, or array of patterns, which specifies the files in the build the plugin should include. By default all svg files will be included.
include: '**/*.svg',
// A minimatch pattern, or array of patterns, which specifies the files in the build the plugin should ignore. By default no files are ignored.
exclude: '',
})
MIT
FAQs
Vite plugin to transform SVGs into React components
The npm package vite-plugin-svgr receives a total of 776,818 weekly downloads. As such, vite-plugin-svgr popularity was classified as popular.
We found that vite-plugin-svgr demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
PyPI now supports digital attestations, enhancing security and trust by allowing package maintainers to verify the authenticity of Python packages.
Security News
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.